﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DataProviderFactory.cs" company="CodePlex">
//   Copyright © CodePlex 2012
// </copyright>
// <summary>
//   Defines the DataProviderFactory type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DataFramework.Factories
{
    using System;
    using System.Data;
    using System.Data.OleDb;

    using DataFramework.Interfaces;

    /// <summary>
    /// Factory to provide the caller with the correct DB Connection based on the systems configuration.
    /// </summary>
    internal static class DataProviderFactory
    {
        /// <summary>
        /// Builds the connection.
        /// </summary>
        /// <returns>A connection for the configured database.</returns>
        internal static IDbConnection BuildConnection()
        {
            IDbConnection conn;
            var type = DatabaseConfiguration.DbType;

            switch (type)
            {
                case DatabaseType.OleDb:
                    conn = new OleDbConnection();
                    break;
                default:
                    throw new NotImplementedException();
            }

            if (string.IsNullOrEmpty(DatabaseConfiguration.InternalConnectionString))
            {
                DatabaseConfiguration.Configure();
            }

            conn.ConnectionString = DatabaseConfiguration.InternalConnectionString;
            return conn;
        }

        /// <summary>
        /// Fetches the helper.
        /// </summary>
        /// <returns>A helper for the configured database.</returns>
        internal static IDatabaseHelper FetchConfiguredHelper()
        {
            var databaseType = DatabaseConfiguration.DbType;

            switch (databaseType)
            {
                case DatabaseType.OleDb: 
                    return new OleDatabaseHelper();
                default: 
                    throw new NotImplementedException();
            }
        }
    }
}
